"""
基础数据类型： int float str bool None
复杂数据类型： list tuple dict

基础数据类型用于存储常用值类型，一个变量可以用于存储一个基础数据类型对应的值
列表：可以存储多个值，一个变量存储多个值
元组：一个变量可以存储多个值，但是多个值确定以后不可以修改
字典：提升查询性能，快速获取值
    列表，取值要依次获取前面所有元素对应地址，效率低  l0 = [True,3.14,"hello","hi",5]
    字典，通过存储额外的键，取值，牺牲空间，减少时间开销 d0 = {key1: value1, key2:value2}
"""

# d0 = {}
# d1 = dict()
# print(type(d0), type(d1))
# d2 = {
#     "name": "zzy",
#     "age": 20,
#     "height": 170.0,
#     "sex": True,
#     "desc": None,
#     "address": ["郑州", "北京"],
#     "hobbys": ("吃饭", "喝酒"),
#     "class": {
#         "name": "python",
#         "addr": "class4",
#         "students": [
#             {
#                 "id": 101,
#                 "name": "马云"
#             },
#             {
#                 "id": 102,
#                 "name": "强东"
#             }
#         ]
#     }
# }
# print(type(d2), d2)
#
# d3 = {
#     "id": 101,
#     # "id": 102,
#     678: "hello",
#     9.8: "引力常量",
#     True: "布尔值",
#     None: "空值",
#     # 列表不能作为字典的键
#     # []: "列表"
#     (): "元组",
#     # 字典不可以作为字典的键
#     # {}: "字典"
#
# }
# print(type(d3), d3)
#


# d4 = {
#     "name": "zzy",
#     "age": 20,
#     "height": 170.0,
#     "sex": True,
#     "desc": None,
#     "address": ["郑州", "北京"],
#     "hobbys": ("吃饭", "喝酒"),
#     "class": {
#         "name": "python",
#         "addr": "class4",
#         "students": [
#             {
#                 "id": 101,
#                 "name": "马云"
#             },
#             {
#                 "id": 102,
#                 "name": "强东"
#             }
#         ]
#     }
# }

# print(d4["name"], d4["class"]["students"][1]["name"])

# print(d4.get("name1", "abc"))
# d4["name1"] = "qiku"
# print(d4.get("name1", "abc"))
# d4["name1"] = "henan"
# print(d4.get("name1", "abc"))


# l0 = [1,2,3,4,5]
# if 3 in l0:
#     print("====")


# if "name2" in d4:
#     print("===")


d0 = {
    "name": "101",
    "age": 50
}

# 取向元组列表遍历写法
# for key in d0:
#     print(key, d0.get(key))


# 遍历所有键 根据键取值
# for key in d0.keys():
#     print(key, d0.get(key))

# 遍历所有值 拿到所有值
# for value in d0.values():
#     print(value)

# for key, value in d0.items():
#     print(key, value)


# d0.keys()
# d0.values()
# d0.items()


# 删除指定键值对  返回键对应的值
# r = d0.pop("name")
# print(r, d0)

# 清空
# d0.clear()
# print(d0)

# 将一个字典所有的键值对加入原始字典
# d0.update({
#     "name": "qiku",
#     "sex": True
# })
#
# print(d0)


# 统计一个字符中各个字符出现的次数

# 方式一使用字典统计
result = {}
s0 = "helloworld"
for c in s0:
    if c in result:
        result[c] += 1
    else:
        result[c] = 1
print(result)

#
# result = [
#
# ]
# s0 = "helloworld"
# for c in s0:
#     for e in result:
#         if e[0] == c:
#             e[1] += 1
#             break
#     else:
#         result.append([c, 1])
# print(result)

